{include file='pub/base' /}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form class="mb-20" method="post" action="{:url('index')}">
	<div class="text-l">
		<input type="text" name='username' class="input-text" style="width:250px" placeholder="输入管理员名称" >
		<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
		<a href="javascript:;" onclick="layer_show('新增管理员','{:url('add')}','850','500')" class="btn btn-primary radius">
	<i class="Hui-iconfont">&#xe600;</i> 添加管理员</a>
	</div>
	</form>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="150">登录名</th>
				<th width="90">手机</th>
				<th width="150">邮箱</th>
				<th>角色</th>
				<th width="130">加入时间</th>
				<th width="100">是否已启用</th>
				<th width="150">操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name='list' id='k'}
			<tr class="text-c">
				<td>{$k.id}</td>
				<td>{$k.username}</td>
				<td>{$k.tel}</td>
				<td>{$k.mail}</td>
				<td>{:get_rolename($k.role)}</td>
				<td>{$k['add_time']|date='Y-m-d H:i'}</td>
				<td class="td-status">
				<span class="label {eq name='$k.status' value='1'}label-success{else/}label-default{/eq} radius">
				{eq name='$k.status' value='1'}已启用{else/}已禁用{/eq}
				</span></td>
				<td class="td-manage">
				{neq name='$k.id' value='1'}
				<div class="btn-group">
					<span class="btn  radius size-S" onclick="layer_show('修改管理员','{:url('edit',['id'=>$k.id])}','850','500')" >修改</span>
					{eq name='$k.status' value='1'}
					<span class="btn  radius size-S" onClick="admin_stop(this,{$k.id})">停用</span>
					{else/}
					<span class="btn  radius size-S" onClick="admin_start(this,{$k.id})">启用</span>
					{/eq}
					<span class="btn  radius size-S"  onclick="admin_del(this,'{$k.id}')"  >删除</span>
				</div>
				</td>
				{else/}
				 内置账号，无法操作
				{/neq}
			</tr>
			{/volist}
		</tbody>
	</table>
</div>

<script type="text/javascript">

/*管理员-删除*/
function admin_del(obj,id){
	layer.confirm('请确认删除？删除后关联业务会出问题，建议采用禁用！',function(index){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url("del")}.?id='+id+'',
			dataType: 'json',
			success: function(data){
				if(data.code==0){
					$(obj).parents("tr").remove();
				}
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
	});
}

/*管理员-停用*/
function admin_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			type: 'POST',
			url: '{:url("change")}.?id='+id+'&status=0',
			dataType: 'json',
			success: function(data){
				if(data.code==0){
					$(obj).parents("tr").find(".td-manage").prepend('<span class="btn  radius size-S" onClick="admin_start(this,id)" >启用</span>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
					$(obj).remove();
					layer.msg('已停用!',{icon: 5,time:1000});
					
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*管理员-启用*/
function admin_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url("change")}.?id='+id+'&status=1',
			dataType: 'json',
			success: function(data){
				if(data.code==0){
				$(obj).parents("tr").find(".td-manage").prepend('<span class="btn  radius size-S" onClick="admin_stop(this,id)" >启用</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
				$(obj).remove();
				layer.msg('已启用!', {icon: 6,time:1000});
			}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});	
	});
}
</script>
</body>
</html>